package service;

import dao.*;
import entity.Result;
import entity.Student;
import entity.Subject;

import java.util.List;

/**
 * @Author:SA
 * @DATA:DATA
 */


public class ResultServiceImpl implements ResultService{

    private StudentDao studentDao = new StudentDaoImpl();
    private ResultDao resultDao = new ResultDaoImpl();
    private SubjectDao subjectDao = new SubjectDaoImpl();
    @Override
    public boolean addResult(String sname, String subname,double garde) {
        //成绩表中记录的是学生的id,科目id  成绩
        //1.根据学生的姓名 查询学生的学号
        Student student = studentDao.selectByName(sname);
        String stuId = student.getId();
        //2.根据科目的名称查询科目编号
       Subject subject = subjectDao.selectByName(subname);
        long subjectId = subject.getId();
        //3.将学生id 科目id 分数添加到result表
        int line =resultDao.addResult(stuId,subjectId,garde);
        return line>0;
    }

    @Override
    public List<Result> seletAll(String subname) {

       List<Result> results=  resultDao.selectAll(subname);


        return results;
    }
}
